package com.example.a2205_fx.database;

import android.app.Application;

import androidx.room.Room;

public class AppDataBaseUtil {
    private AppDataBaseUtil(){}
    private static AppDataBaseUtil appDataBaseUtil = new AppDataBaseUtil();
    public static  AppDataBaseUtil getInstance(){
        return appDataBaseUtil;
    }
    private AppDataBase appDataBase;
    private VideoDao videoDao;
    private AccountDao accountDao;

    public void init(Application application){
        appDataBase = Room.databaseBuilder(application,AppDataBase.class,"fx.db")
                .allowMainThreadQueries()
                .build();
        videoDao = appDataBase.getVideoDao();
        accountDao = appDataBase.getAccountDao();
    }

    public VideoDao getVideoDao(){
        if(videoDao==null){
            videoDao = appDataBase.getVideoDao();
        }
        return videoDao;
    }
    public AccountDao getAccountDao(){
        if(accountDao==null){
            accountDao = appDataBase.getAccountDao();
        }
        return accountDao;
    }
}
